package com.commons.base.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.apache.commons.lang.StringUtils;


/**
 * 说明：
 * 
 * @author: xkq
 * @Package com.hy.common.util
 * @Description: TODO(用一句话描述该文件做什么)
 * @author xkq
 * @date 2018年5月4日
 */

public class StrUtils {
	public static List<String> str_comma_list(String data) {
		return str_comma_list(data, true);
	}

	/**
	 * 
	 * 此方法描述的是：
	 * 
	 * @param data
	 * @param isQC
	 *            true 去重
	 * @return List<String>
	 */
	public static List<String> str_comma_list(String data, boolean isQC) {
		if (StringUtils.isNotBlank(data)) {
			String[] strList = data.split(",");
			List<String> list = Arrays.asList(strList);
			if (isQC) {
				list = new ArrayList<>(new HashSet<>(list));
			}
			return list;
		}
		return new ArrayList<String>();
	}
	
	
	public static  String phone_middle_hide(String phone){
		if(StringUtils.isBlank(phone) ||phone.length()<11){
			return phone;
		}
		if(phone.length()>11){
			phone = phone.substring(0, 11);
		}
		phone = phone.substring(0, 3)+create_hide_symbol(4)+phone.substring(7, phone.length());
		return phone;
	}
	public static String name_right_hide(String name){
		if(StringUtils.isBlank(name)||name.length()<=1){
			return name;
		}
		name = name.substring(0,1)+create_hide_symbol(name.length()-1);
		return name;
	}
	public static String identity_left_hide(String identityCode){
		if(StringUtils.isBlank(identityCode)||identityCode.length()<=4){
			return identityCode;
		}
		return create_hide_symbol(identityCode.length()-4)+StringUtils.right(identityCode, 4);
	}
	private static String create_hide_symbol(int size){
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < size; i++) {
			sb.append("*");
		}
		return sb.toString();
	}
}
